package com.tianqu.tms.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.dao.CarStyleDao;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dto.CarStyleDto;

/**
 * 车辆款式字典表
 * 
 * @author tianshifu
 *
 */

public class CarStyle extends TmsEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5070305928983918814L;

	private String carStyleId;// 款式ID

	private String carStyleName;// 款式全名

	private String carStyleRealName;// 款式真实名

	private String carStylePinYin;// 款式拼音

	private String search;//款式检索?

	private float exhaust;// 排量

	private int gearbox;// 变速箱类型

	private String brandId;// 车系ID
	
	private int carType;//
	
	private String vendorId;// 品牌ID
	
	/**
	 * 实例化codes表
	 * 
	 * @return
	 */
	private static CarStyle instance;

	List<CarStyle> codes = null;
	
	/**
	 * 加载Codes
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public static CarStyle getInstance() throws TmsDaoException {
		if (null == instance) {
			instance = new CarStyle();
			instance.init();
		}
		return instance;
	}

	/**
	 * 实例化Code
	 * 
	 * @throws TmsDaoException
	 */
	public void init() throws TmsDaoException {
		codes = new ArrayList<CarStyle>();
		setCodes();
	}
	
	/**
	 * 获取Codes信息存在静态codes中
	 * @throws TmsDaoException
	 */
	public void setCodes() throws TmsDaoException {
		CarStyleDao dao = (CarStyleDao) TmsDao.getInstance(TmsDao.TMS_CAR_STYLE);
		List<CarStyleDto> list = dao.findAllCarStyleInfo();
		for (int i = 0; i < list.size(); i++) {
			CarStyleDto dto = (CarStyleDto) list.get(i);
			CarStyle entity = new CarStyle();
			entity.setBrandId(dto.getBrandId());
			entity.setCarStyleId(dto.getCarStyleId());
			entity.setCarStyleName(dto.getCarStyleName());
			entity.setCarStylePinYin(dto.getCarStylePinYin());
			entity.setCarStyleRealName(dto.getCarStyleRealName());
			entity.setSearch(dto.getSearch());
			entity.setGearbox(dto.getGearbox());
			entity.setExhaust(dto.getExhaust());
			entity.setCarType(dto.getCarType());
			codes.add(entity);
		}
	}
	/**
	 * 根据车辆车系ID获取款式下拉列表
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List getAllCarStyleInfo(String brandId)
	{
		List list = new ArrayList();
		Map map = null;
		for(int i=0;i<codes.size();i++)
		{
			CarStyle entity = codes.get(i);
			if(entity.getBrandId().equals(brandId))
			{
				map = new HashMap();
				map.put("carStyleId", entity.getCarStyleId());
				map.put("carStyleName", entity.getCarStyleName());
				list.add(map);
			}
		}
		
		return list;
	}
	/**
	 * 根据车辆款式ID获取车系ID
	 * @return
	 */
	public String getBrandIDByCarStyleID(String carStyleId)
	{
		String brandId = "";
		for(int i=0;i<codes.size();i++)
		{
			CarStyle entity = codes.get(i);
			if(entity.getCarStyleId().equals(carStyleId))
			{
				brandId = entity.getBrandId();
			}
		}
		
		return brandId;
	}
	/**
	 * 根据ID获取排量
	 * @return
	 */
	public float getExhaustByCarStyleId(String carStyleId){
		for(int i=0;i<codes.size();i++)
		{
			CarStyle entity = (CarStyle)codes.get(i);
			if(entity.getCarStyleId().equals(carStyleId))
			{
				return entity.getExhaust();
			}
		}
		return 0;
	}
	/**
	 * 根据款式ID获取变速箱code
	 * 这个返回-1
	 * @return
	 */
	public int getGearboxByCarStyleId(String carStyleId)
	{
		for(int i=0;i<codes.size();i++)
		{
			CarStyle entity = (CarStyle)codes.get(i);
			if(entity.getCarStyleId().equals(carStyleId))
			{
				return entity.getGearbox();
			}
		}
		return -1;
	}
	
	/**
	 * 根据款式ID获取车辆名称
	 * @return
	 */
	
	public String getCarStyleRealNameById(String carStyleId){
		
		for(int i=0;i<codes.size();i++)
		{
			CarStyle entity = (CarStyle)codes.get(i);
			if(entity.getCarStyleId().equals(carStyleId))
			{
				return entity.getCarStyleRealName();
			}
		}
		return "";
	}

	/**
	 * 根据款式ID获取车辆名称
	 * @return
	 */
	
	public String getCarStyleRNameById(String carStyleId){
		
		for(int i=0;i<codes.size();i++)
		{
			CarStyle entity = (CarStyle)codes.get(i);
			if(entity.getCarStyleId().equals(carStyleId))
			{
				return entity.getCarStyleName();
			}
		}
		return "";
	}
	/**
	 * 获取Codes信息存在静态codes中
	 * @throws TmsDaoException
	 */
	public CarStyle findCarStyleInfo(String modelIdOther) throws TmsDaoException {
		CarStyleDao dao = (CarStyleDao) TmsDao.getInstance(TmsDao.TMS_CAR_STYLE);
		CarStyleDto dto = dao.findCarStyleInfo(modelIdOther);
		CarStyle carStyle = new CarStyle();
		if(dto != null){
			carStyle.setCarStyleName(dto.getCarStyleName());
			carStyle.setCarStyleId(dto.getCarStyleId());
			carStyle.setBrandId(dto.getBrandId());
			carStyle.setVendorId(dto.getVendorId());
		}
		return carStyle;
	}

    /**
     * 获取Codes信息存在静态codes中
     * @throws TmsDaoException
     */
    public CarStyle findCarStyleInfoByModelId(String modelId) throws TmsDaoException {
        CarStyleDao dao = (CarStyleDao) TmsDao.getInstance(TmsDao.TMS_CAR_STYLE);
        CarStyleDto dto = dao.findCarStyleInfoByModelId(modelId);
        CarStyle carStyle = new CarStyle();
        if(dto != null){
            carStyle.setCarStyleName(dto.getCarStyleName());
            carStyle.setCarStyleId(dto.getCarStyleId());
            carStyle.setBrandId(dto.getBrandId());
            carStyle.setVendorId(dto.getVendorId());
        }
        return carStyle;
    }
	
	public CarStyleDto getCarStyleInfo(String id) throws TmsDaoException{
		 CarStyleDao dao = (CarStyleDao) TmsDao.getInstance(TmsDao.TMS_CAR_STYLE);
		 return dao.getCarStyleInfo(id);
	}
	
	public int getCarType() {
		return carType;
	}

	public void setCarType(int carType) {
		this.carType = carType;
	}



	public String getCarStyleId() {
		return carStyleId;
	}

	public void setCarStyleId(String carStyleId) {
		this.carStyleId = carStyleId;
	}

	public String getBrandId() {
		return brandId;
	}

	public void setBrandId(String brandId) {
		this.brandId = brandId;
	}

	public String getCarStyleName() {
		return carStyleName;
	}

	public void setCarStyleName(String carStyleName) {
		this.carStyleName = carStyleName;
	}

	public String getCarStyleRealName() {
		return carStyleRealName;
	}

	public void setCarStyleRealName(String carStyleRealName) {
		this.carStyleRealName = carStyleRealName;
	}

	public String getCarStylePinYin() {
		return carStylePinYin;
	}

	public void setCarStylePinYin(String carStylePinYin) {
		this.carStylePinYin = carStylePinYin;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	
	public float getExhaust() {
		return exhaust;
	}

	public void setExhaust(float exhaust) {
		this.exhaust = exhaust;
	}

	public int getGearbox() {
		return gearbox;
	}

	public void setGearbox(int gearbox) {
		this.gearbox = gearbox;
	}


	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub

	}

	/**
	 * @param vendorId the vendorId to set
	 */
	public void setVendorId(String vendorId) {
		this.vendorId = vendorId;
	}

	/**
	 * @return the vendorId
	 */
	public String getVendorId() {
		return vendorId;
	}

}
